import util from '@/utils/util.js';

export default {
    data() {
        return {

        }
    },
    onLoad() {

    },
    methods: {
        openPage(options, callback) {
            //options.CustomWindow参数控制是否重置自定义组件
            if (!options.CustomWindow) {
                getApp().globalData.CustomWindow = [];
            }
            return util.openPage(options, callback);
        },
        callbackPage(data) {
            const eventChannel = this.getOpenerEventChannel()
            eventChannel.emit('callbackFromOpenedPage', data);
        },
        closePage(options) {
            // if(!options.CustomWindow){
            // 	getApp().globalData.CustomWindow=[];
            // }
            util.closePage(options);
        },
        showMsg: function(msg, delay, fn) {
            return util.showMsg(msg, delay, fn);
        },
        refreshPage(params) {
            var pages = getCurrentPages();
            var page = pages[pages.length - 1];
            var url = "/" + page.route;
            uni.redirectTo({
                url: url,
                success(res) {
                    console.log(res);
                    if (params) {
                        // 通过eventChannel向被打开页面传送数据
                        res.eventChannel.emit('acceptDataFromOpenerPage', params)
                    }
                }
            });
        },
        showWait: function(msg) {
            msg = msg || '数据加载中……';
            return util.showWait(msg);
        },
        hideWait() {
            return util.hideWait();
        },
        alert: function(msg, title) {
            return util.alert(msg, title);
        },
        confirm: function(msg, callback, title) {
            return util.confirm(msg, callback, title);
        },
    }
}
